<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Safe #-}</span><span>
</span><span id="line-2"></span><span>
</span><span id="line-3"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- Module      :  Data.Ratio</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- </span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Stability   :  stable</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Standard functions on rational numbers</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Ratio</span><span>
</span><span id="line-18"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Real.html#Ratio"><span class="hs-identifier">Ratio</span></a></span><span>
</span><span id="line-19"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Real.html#Rational"><span class="hs-identifier">Rational</span></a></span><span>
</span><span id="line-20"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Real.html#%25"><span class="hs-operator">(%)</span></a></span><span>
</span><span id="line-21"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Real.html#numerator"><span class="hs-identifier">numerator</span></a></span><span>
</span><span id="line-22"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Real.html#denominator"><span class="hs-identifier">denominator</span></a></span><span>
</span><span id="line-23"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Ratio.html#approxRational"><span class="hs-identifier">approxRational</span></a></span><span>
</span><span id="line-24"></span><span>
</span><span id="line-25"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-26"></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>         </span><span class="hs-comment">-- The basic defns for Ratio</span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- approxRational</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-comment">-- | 'approxRational', applied to two real fractional numbers @x@ and @epsilon@,</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- returns the simplest rational number within @epsilon@ of @x@.</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- A rational number @y@ is said to be /simpler/ than another @y'@ if</span><span>
</span><span id="line-35"></span><span class="hs-comment">--</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- * @'abs' ('numerator' y) &lt;= 'abs' ('numerator' y')@, and</span><span>
</span><span id="line-37"></span><span class="hs-comment">--</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- * @'denominator' y &lt;= 'denominator' y'@.</span><span>
</span><span id="line-39"></span><span class="hs-comment">--</span><span>
</span><span id="line-40"></span><span class="hs-comment">-- Any real interval contains a unique simplest rational;</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- in particular, note that @0\/1@ is the simplest rational of all.</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-comment">-- Implementation details: Here, for simplicity, we assume a closed rational</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- interval.  If such an interval includes at least one whole number, then</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- the simplest rational is the absolutely least whole number.  Otherwise,</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- the bounds are of the form q%1 + r%d and q%1 + r'%d', where abs r &lt; d</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- and abs r' &lt; d', and the simplest rational is q%1 + the reciprocal of</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- the simplest rational between d'%r' and d%r.</span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span id="local-6989586621679565759"><span class="annot"><a href="Data.Ratio.html#approxRational"><span class="hs-identifier hs-type">approxRational</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Real.html#RealFrac"><span class="hs-identifier hs-type">RealFrac</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679565759"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679565759"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679565759"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Real.html#Rational"><span class="hs-identifier hs-type">Rational</span></a></span></span><span>
</span><span id="line-51"></span><span id="approxRational"><span class="annot"><span class="annottext">approxRational :: forall a. RealFrac a =&gt; a -&gt; a -&gt; Rational
</span><a href="Data.Ratio.html#approxRational"><span class="hs-identifier hs-var hs-var">approxRational</span></a></span></span><span> </span><span id="local-6989586621679565727"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565727"><span class="hs-identifier hs-var">rat</span></a></span></span><span> </span><span id="local-6989586621679565726"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565726"><span class="hs-identifier hs-var">eps</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-52"></span><span>    </span><span class="hs-comment">-- We convert rat and eps to rational *before* subtracting/adding since</span><span>
</span><span id="line-53"></span><span>    </span><span class="hs-comment">-- otherwise we may overflow. This was the cause of #14425.</span><span>
</span><span id="line-54"></span><span>    </span><span class="annot"><span class="annottext">Rational -&gt; Rational -&gt; Rational
forall {a}. Real a =&gt; a -&gt; a -&gt; Rational
</span><a href="#local-6989586621679565725"><span class="hs-identifier hs-var">simplest</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Rational
forall a. Real a =&gt; a -&gt; Rational
</span><a href="GHC.Real.html#toRational"><span class="hs-identifier hs-var">toRational</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565727"><span class="hs-identifier hs-var">rat</span></a></span><span> </span><span class="annot"><span class="annottext">Rational -&gt; Rational -&gt; Rational
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Rational
forall a. Real a =&gt; a -&gt; Rational
</span><a href="GHC.Real.html#toRational"><span class="hs-identifier hs-var">toRational</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565726"><span class="hs-identifier hs-var">eps</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Rational
forall a. Real a =&gt; a -&gt; Rational
</span><a href="GHC.Real.html#toRational"><span class="hs-identifier hs-var">toRational</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565727"><span class="hs-identifier hs-var">rat</span></a></span><span> </span><span class="annot"><span class="annottext">Rational -&gt; Rational -&gt; Rational
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Rational
forall a. Real a =&gt; a -&gt; Rational
</span><a href="GHC.Real.html#toRational"><span class="hs-identifier hs-var">toRational</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565726"><span class="hs-identifier hs-var">eps</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-56"></span><span>    </span><span id="local-6989586621679565725"><span class="annot"><span class="annottext">simplest :: a -&gt; a -&gt; Rational
</span><a href="#local-6989586621679565725"><span class="hs-identifier hs-var hs-var">simplest</span></a></span></span><span> </span><span id="local-6989586621679565702"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565702"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679565701"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565701"><span class="hs-identifier hs-var">y</span></a></span></span><span>
</span><span id="line-57"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565701"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565702"><span class="hs-identifier hs-var">x</span></a></span><span>      </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Rational
</span><a href="#local-6989586621679565725"><span class="hs-identifier hs-var">simplest</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565701"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565702"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-58"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565702"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565701"><span class="hs-identifier hs-var">y</span></a></span><span>     </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Rational
</span><a href="#local-6989586621679565699"><span class="hs-identifier hs-var">xr</span></a></span><span>
</span><span id="line-59"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565702"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span>      </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer -&gt; Integer -&gt; Rational
forall {p}. Integral p =&gt; p -&gt; p -&gt; p -&gt; p -&gt; Ratio p
</span><a href="#local-6989586621679565697"><span class="hs-identifier hs-var">simplest'</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565696"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565695"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565694"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565693"><span class="hs-identifier hs-var">d'</span></a></span><span>
</span><span id="line-60"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565701"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span>      </span><span class="hs-glyph">=</span><span>  </span><span class="hs-glyph">-</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer -&gt; Integer -&gt; Rational
forall {p}. Integral p =&gt; p -&gt; p -&gt; p -&gt; p -&gt; Ratio p
</span><a href="#local-6989586621679565697"><span class="hs-identifier hs-var">simplest'</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565694"><span class="hs-identifier hs-var">n'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565693"><span class="hs-identifier hs-var">d'</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565696"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679565695"><span class="hs-identifier hs-var">d</span></a></span><span>
</span><span id="line-61"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Rational
forall a. a -&gt; a -&gt; Ratio a
</span><a href="GHC.Real.html#%3A%25"><span class="hs-operator hs-var">:%</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">1</span></span><span>
</span><span id="line-62"></span><span>      </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679565699"><span class="annot"><span class="annottext">xr :: Rational
</span><a href="#local-6989586621679565699"><span class="hs-identifier hs-var hs-var">xr</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Rational
forall a. Real a =&gt; a -&gt; Rational
</span><a href="GHC.Real.html#toRational"><span class="hs-identifier hs-var">toRational</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565702"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-63"></span><span>            </span><span id="local-6989586621679565696"><span class="annot"><span class="annottext">n :: Integer
</span><a href="#local-6989586621679565696"><span class="hs-identifier hs-var hs-var">n</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Rational -&gt; Integer
forall a. Ratio a -&gt; a
</span><a href="GHC.Real.html#numerator"><span class="hs-identifier hs-var">numerator</span></a></span><span> </span><span class="annot"><span class="annottext">Rational
</span><a href="#local-6989586621679565699"><span class="hs-identifier hs-var">xr</span></a></span><span>
</span><span id="line-64"></span><span>            </span><span id="local-6989586621679565695"><span class="annot"><span class="annottext">d :: Integer
</span><a href="#local-6989586621679565695"><span class="hs-identifier hs-var hs-var">d</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Rational -&gt; Integer
forall a. Ratio a -&gt; a
</span><a href="GHC.Real.html#denominator"><span class="hs-identifier hs-var">denominator</span></a></span><span> </span><span class="annot"><span class="annottext">Rational
</span><a href="#local-6989586621679565699"><span class="hs-identifier hs-var">xr</span></a></span><span>
</span><span id="line-65"></span><span>            </span><span id="local-6989586621679565690"><span class="annot"><span class="annottext">nd' :: Rational
</span><a href="#local-6989586621679565690"><span class="hs-identifier hs-var hs-var">nd'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Rational
forall a. Real a =&gt; a -&gt; Rational
</span><a href="GHC.Real.html#toRational"><span class="hs-identifier hs-var">toRational</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679565701"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-66"></span><span>            </span><span id="local-6989586621679565694"><span class="annot"><span class="annottext">n' :: Integer
</span><a href="#local-6989586621679565694"><span class="hs-identifier hs-var hs-var">n'</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Rational -&gt; Integer
forall a. Ratio a -&gt; a
</span><a href="GHC.Real.html#numerator"><span class="hs-identifier hs-var">numerator</span></a></span><span> </span><span class="annot"><span class="annottext">Rational
</span><a href="#local-6989586621679565690"><span class="hs-identifier hs-var">nd'</span></a></span><span>
</span><span id="line-67"></span><span>            </span><span id="local-6989586621679565693"><span class="annot"><span class="annottext">d' :: Integer
</span><a href="#local-6989586621679565693"><span class="hs-identifier hs-var hs-var">d'</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Rational -&gt; Integer
forall a. Ratio a -&gt; a
</span><a href="GHC.Real.html#denominator"><span class="hs-identifier hs-var">denominator</span></a></span><span> </span><span class="annot"><span class="annottext">Rational
</span><a href="#local-6989586621679565690"><span class="hs-identifier hs-var">nd'</span></a></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span>    </span><span id="local-6989586621679565697"><span class="annot"><span class="annottext">simplest' :: p -&gt; p -&gt; p -&gt; p -&gt; Ratio p
</span><a href="#local-6989586621679565697"><span class="hs-identifier hs-var hs-var">simplest'</span></a></span></span><span> </span><span id="local-6989586621679565674"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565674"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679565673"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565673"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span id="local-6989586621679565672"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565672"><span class="hs-identifier hs-var">n'</span></a></span></span><span> </span><span id="local-6989586621679565671"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565671"><span class="hs-identifier hs-var">d'</span></a></span></span><span>       </span><span class="hs-comment">-- assumes 0 &lt; n%d &lt; n'%d'</span><span>
</span><span id="line-70"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565670"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">p -&gt; p -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-number">0</span></span><span>     </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565669"><span class="hs-identifier hs-var">q</span></a></span><span> </span><span class="annot"><span class="annottext">p -&gt; p -&gt; Ratio p
forall a. a -&gt; a -&gt; Ratio a
</span><a href="GHC.Real.html#%3A%25"><span class="hs-operator hs-var">:%</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-number">1</span></span><span>
</span><span id="line-71"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565669"><span class="hs-identifier hs-var">q</span></a></span><span> </span><span class="annot"><span class="annottext">p -&gt; p -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565667"><span class="hs-identifier hs-var">q'</span></a></span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565669"><span class="hs-identifier hs-var">q</span></a></span><span class="annot"><span class="annottext">p -&gt; p -&gt; p
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">p
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">p -&gt; p -&gt; Ratio p
forall a. a -&gt; a -&gt; Ratio a
</span><a href="GHC.Real.html#%3A%25"><span class="hs-operator hs-var">:%</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-number">1</span></span><span>
</span><span id="line-72"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565669"><span class="hs-identifier hs-var">q</span></a></span><span class="annot"><span class="annottext">p -&gt; p -&gt; p
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565665"><span class="hs-identifier hs-var">n''</span></a></span><span class="annot"><span class="annottext">p -&gt; p -&gt; p
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565664"><span class="hs-identifier hs-var">d''</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">p -&gt; p -&gt; Ratio p
forall a. a -&gt; a -&gt; Ratio a
</span><a href="GHC.Real.html#%3A%25"><span class="hs-operator hs-var">:%</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565665"><span class="hs-identifier hs-var">n''</span></a></span><span>
</span><span id="line-73"></span><span>      </span><span class="hs-keyword">where</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679565669"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565669"><span class="hs-identifier hs-var">q</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679565670"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565670"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">)</span><span>      </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">p -&gt; p -&gt; (p, p)
forall a. Integral a =&gt; a -&gt; a -&gt; (a, a)
</span><a href="GHC.Real.html#quotRem"><span class="hs-identifier hs-var">quotRem</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565674"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565673"><span class="hs-identifier hs-var">d</span></a></span><span>
</span><span id="line-74"></span><span>            </span><span class="hs-special">(</span><span id="local-6989586621679565667"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565667"><span class="hs-identifier hs-var">q'</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679565660"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565660"><span class="hs-identifier hs-var">r'</span></a></span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">p -&gt; p -&gt; (p, p)
forall a. Integral a =&gt; a -&gt; a -&gt; (a, a)
</span><a href="GHC.Real.html#quotRem"><span class="hs-identifier hs-var">quotRem</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565672"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565671"><span class="hs-identifier hs-var">d'</span></a></span><span>
</span><span id="line-75"></span><span>            </span><span id="local-6989586621679565659"><span class="annot"><span class="annottext">nd'' :: Ratio p
</span><a href="#local-6989586621679565659"><span class="hs-identifier hs-var hs-var">nd''</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">p -&gt; p -&gt; p -&gt; p -&gt; Ratio p
</span><a href="#local-6989586621679565697"><span class="hs-identifier hs-var">simplest'</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565671"><span class="hs-identifier hs-var">d'</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565660"><span class="hs-identifier hs-var">r'</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565673"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621679565670"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-76"></span><span>            </span><span id="local-6989586621679565665"><span class="annot"><span class="annottext">n'' :: p
</span><a href="#local-6989586621679565665"><span class="hs-identifier hs-var hs-var">n''</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Ratio p -&gt; p
forall a. Ratio a -&gt; a
</span><a href="GHC.Real.html#numerator"><span class="hs-identifier hs-var">numerator</span></a></span><span> </span><span class="annot"><span class="annottext">Ratio p
</span><a href="#local-6989586621679565659"><span class="hs-identifier hs-var">nd''</span></a></span><span>
</span><span id="line-77"></span><span>            </span><span id="local-6989586621679565664"><span class="annot"><span class="annottext">d'' :: p
</span><a href="#local-6989586621679565664"><span class="hs-identifier hs-var hs-var">d''</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Ratio p -&gt; p
forall a. Ratio a -&gt; a
</span><a href="GHC.Real.html#denominator"><span class="hs-identifier hs-var">denominator</span></a></span><span> </span><span class="annot"><span class="annottext">Ratio p
</span><a href="#local-6989586621679565659"><span class="hs-identifier hs-var">nd''</span></a></span><span>
</span><span id="line-78"></span><span>
</span><span id="line-79"></span></pre></body></html>